<?php
require_once(dirname(__FILE__)."/constants.php");
/*
 * Created on 2007-11-18
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

function GeoDegree2GoogleStd($degree) {
	return intval($degree * 1000000);
}

function GetCurrentDateTime2DbFormat()
{
	$dt = getdate();
	$year 	= $dt['year'];
	$month 	= $dt['mon'];
	$day 	= $dt['mday'];
	$hours 	= $dt['hours'];
	$minutes= $dt['minutes'];
	$seconds= $dt['seconds'];
	
	$ret = $year."-".$month."-".$day." ".$hours.":".$minutes.":".$seconds;
	return $ret;
}

function GetDateTimeSeconds() {
	$now_sec = time();
	return $now_sec;
}

class DateUtils {
	const FMT_DEFAULT = 'Y-m-j H:i:s';
}

class StringUtils {
	public static function is_end_with($haystack, $needle, $ignore_case = FALSE) {
		if ((gettype($haystack) != gettype("")) ||
			(gettype($needle) != gettype(""))) {
			return FALSE;
		}
		else {
			$last_pos = FALSE;
			if ($ignore_case)
				$last_pos = strripos($haystack, $needle);
			else
				$last_pos = strrpos($haystack, $needle);
				
			if ($last_pos == FALSE) {
				return FALSE;
			}
			/*
			 * Needle is found.
			 */
			return ( ($last_pos + strlen($needle)) == (strlen($haystack)) );
		}
	}
	
	public static function is_start_with($haystack, $needle, $ignore_case = FALSE) {
		if ((gettype($haystack) != gettype("")) ||
			(gettype($needle) != gettype(""))) {
			return FALSE;
		}
		else {
			$start_pos = FALSE;
			if ($ignore_case)
				$start_pos = stripos($haystack, $needle);
			else
				$start_pos = strpos($haystack, $needle);
			
			/*
			 * Needle is found.
			 */
			if ($start_pos === FALSE)
				return FALSE;
			else if ($start_pos === 0)
				return TRUE;
			else
				return FALSE;
		}
	}
	
	public static function TrimLastSlash(& $target) {
		if (StringUtils::is_end_with($target, "/")) {
			$target = substr($target, 0, strlen($target) - 1);
		}
	}
}

function GetUserIcon($uid) {
	$file = "images/no_photo.png";
	
	$file_name = UserManager::GetIconByUID($uid);
	if ($file_name != null)
		$file = $file_name;
		
	return $file;
}

?>
